package spring.service.impl;

import spring.dao.UserDao;
import spring.dao.impl.UserDaoImpl;
import spring.entity.User;
import spring.factory.UserDaoFactory;
import spring.service.UserService;

/**
 * 用户模块业务层实现
 */
public class UserServiceImpl implements UserService {
//    //实例化所依赖的UserDao对象
////    private UserDao dao=new UserDaoImpl();
//
//    //通过工厂获取所依赖的UserDao对象
//    private UserDao dao= UserDaoFactory.getInstance();

    /**
     * 声明接口类型的引用，和具体实现类解耦合
     */
    private UserDao userDao;

    /**
     * 保护用户信息
     */
    public void save(User user){
        //调用UserDao的方法保存用户信息
        userDao.save(user);
    }
    /**
     * dao属性的setter访问器，会被spring调用，实现依赖注入
     */
    public void setUserDao(UserDao userDao){
        this.userDao=userDao;
    }
}
